
import useCustomerStore from "@src/store/customerStore";
import { get, post, upload} from "@src/network/axios";
import defaults, { conversationRelation } from "@src/store/defaults";
import { url } from "inspector";
import { IServiceLogin, IWebsiteBaseInfo, IFileUpLoad, IGetHistory, IGetConversationRelationHistory } from "@src/types";
/*
用户侧接口
*/
export async function serviceLogin(username:string, password:string) {
    const response = await post<IServiceLogin>('aichat/v1/login/serviceLogin',{account:username,password:password});
    return response;
    // return {
    //     website:response.data.website,
    //     services:response.data.services,
    //     conversationRelations:response.data.conversationRelations,
    //     customers:response.data.customers
    // }
}

export async function getCustomerBaseInfo(websiteId:string,customerId?:string) {
    const response = await post<IWebsiteBaseInfo>('aichat/v1/website/baseInfo',{website_id:websiteId,customer_session_id:customerId});
    console.log(response)
    return {
        services:response.data.services,
        website:response.data.website,
        conversation:response.data.conversations,
        customer:response.data.customer
    }
}

export async function updateRelationStatus(realtionId:number,status:number) {
    console.log('updatestatus ' + realtionId + ' ' + status)
    const response = await post('aichat/v1/conversationRelation/updateStatus',{conversation_relation_id:realtionId,status:status});
    return response
}

export async function uploadFile(data:FormData) {
    const response = await upload<IFileUpLoad>('/aichat/v1/file/upload',data);
    return response
}

export async function getHistory(customer_id:number,website_id:number,start_id:number,size:number) {
    const response = await post<IGetHistory>('/aichat/v1/conversation/getMore',{
        customer_id,website_id,start_id,size
    });
    return response
}


export async function getConversationRelationHistory(website_id:number,service_id:number = -1,day:number = 30) {
    const response = await post<IGetConversationRelationHistory>('/aichat/v1/conversationRelation/history',{
        website_id,service_id,day
    });
    return response
}
/*
客服侧接口
*/
export async function getServiceBaseInfo(serviceId:number) {
    return {
        services:defaults.serviceUser,
        website:defaults.website,
        conversation:defaults.conversations,
        customer:defaults.customerUser,
        conversationRelation: defaults.conversationRelation
    }
}


/*
管理员接口
*/
export async function adminLogin(username:string,password:string) {
    const response = await post('aichat/v1/login/adminLogin');
    console.log(response)
}